Repository navigation
Verify a contract with its inherited members - #21
Open
evertonfraga wants to merge 4 commits into
Open
evertonfraga wants to merge 4 commits into
evertonfraga wants to merge 4 commits into
Conversation
solc does not flatten inherited members into a derived contract, so a contract that used anything its base declared failed to translate (`Resolution failed: 'n' is not defined`). A contract is now verified as the flattening of its bases and itself, in its own context: inherited state variables, functions, modifiers, structs, enums and invariants resolve, an inherited function calls the most derived override of a virtual function, and a base's invariants are checked at every entry point. Each contract of the file is still verified on its own. - Bases are ordered by solc's C3 linearization. - A function overrides one with the same name and parameter types (data locations aside); an overload stays. A public state variable overrides the base function its getter implements. - An obligation of an inherited function names the contract it is checked in, `ensures … (in Fast)`, as the same clause is checked once per contract that inherits it. An inherited `assert` is still classified `strata/assert-fail` in SARIF. - A base that the file does not define, directly or through another base, is reported for each contract that inherits it. Rejected for now: a base constructor that does anything, `super`, and a state variable declared again in a derived contract (a base's private one is a different variable).
A constructor of a contract with bases now first runs the base constructors, as solc's legacy code generator does: - after the state-variable initializers, outside the constructor's own modifiers, most base first; - each with its own modifiers, in a block that its `return` exits, so an early return ends that constructor only; - with its parameters and locals renamed apart from the derived constructor's (`__ctor_<Base>_<name>`); - with the arguments that the most derived constructor naming the base gives (`constructor() Base(7)`), evaluated most derived first, so an argument may read the parameters of the constructor that gives it. An inheritance specifier's arguments (`is Base(7)`) are not in the AST: those parameters are unknown values of their types. The implicit constructor that checks a contract's initial state runs them too. A constructor that runs a base constructor using a struct-valued mapping is not verified, as one using it itself is not (reported). The modifier inlining of `translateFunction` is now `inlineModifiers`, shared with the base constructors; a function's labels are unchanged.
…ntations `super.f(…)` calls the implementation of `f` that follows, in the linearization of the contract being verified, the contract the call is written in: a function's, a modifier's (the contract defining the modifier) or a base constructor's. So the same body can call different implementations in different contracts. `Base.f(…)` calls the first implementation in Base's own linearization. An overridden implementation that such a call reaches, directly or through another one, is emitted as the internal procedure `__base_<Contract>_<f>` of the contract being verified, with its own specification; one no call reaches is not. A call that reaches the implementation the contract keeps calls that procedure. Named arguments bind by name. Rejected: `super.f(…)` of an overloaded `f`, and a call reaching an implementation that uses a struct-valued mapping. inheritance_linearization.sol pins C3 order through base constructors: a depth-first order of the base lists runs them in a different order and gives a different result.
The documentation called inheritance accepted and "flattened at the AST level" (supported_features.md, REQ-SOL-004/005) and also "single contract only, no virtual dispatch" (LIMITATIONS.md, GAP-009); FAQ.md and the overview said Solidity has no dynamic dispatch to model. All now describe what is verified, what is reported (a base in another file) and what is rejected or read as unknown. Adds .kiro/specs/strata-solidity-next/requirements.md, the follow-on spec CONTRIBUTING.md requires for closing a gap: REQ-NEXT-SOL-001..025 close GAP-009 except for the cases they report or reject, cite REQ-SOL-004..006, and leave the baseline unchanged. CHANGELOG.md has an entry.
evertonfraga
force-pushed
the
feat/inheritance
branch
from
October 23, 2026 16:21
72b3735 to
1a76458
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A contract is now verified together with what it inherits. Before,
contract Child is Basefailed to translate (Resolution failed: 'n' is not defined) as soon as it used anythingBasedeclared.Stacked on #25 (soundness fixes), which is stacked on #23 (per-obligation goldens). Review after those.
feat(translator): verify a contract with its inherited memberslinearizedBaseContracts), computed from theislists.ensures … (in D). The same clause is checked once per contract that inherits it. An inheritedassertis still classifiedstrata/assert-failin SARIF.feat(translator): run base constructors when a derived contract deploysA derived contract's constructor first runs its base constructors, as solc's legacy code generator does:
returnexits;constructor() Base(7)). These are evaluated most derived first, so an argument may read the parameters of the constructor that gives it.Arguments in an inheritance specifier (
is Base(7)) are not in the AST the translator reads: those parameters get unknown values of their types.The implicit constructor that checks a contract's initial state runs base constructors too. A constructor that runs a base constructor using a struct-valued mapping is not verified, and this is reported.
translateFunction's modifier inlining is nowinlineModifiers, shared with base constructors.feat(translator): super.f(…) and Base.f(…) call inherited implementationssuper.f(…)calls the implementation offthat follows, in the linearization of the contract being verified, the contract the call is written in. That contract is the one defining the function, modifier or base constructor containing the call.Base.f(…)calls the first implementation inBase's own linearization.__base_<Contract>_<f>; an unreached one is not emitted.superof an overloaded function, and a call reaching an implementation that uses a struct-valued mapping.docs: describe inheritance as the translator now verifies itLIMITATIONS.md,FAQ.mdand the guide (limitations.md,supported_features.md,overview.md). They had called inheritance both "flattened at the AST level" and "single contract only, no virtual dispatch".CHANGELOG.md..kiro/specs/strata-solidity-next/requirements.md: REQ-NEXT-SOL-001..025 close GAP-009 except for the cases reported, rejected or read as unknown.Testing
// Passes/// Refuted/// Not provencomments:inheritance.sol: state, modifiers, internal calls, invariants, virtual dispatch, getter overrideinheritance_overloads.solinheritance_constructors.sol: order against modifiers, base modifiers,return, locals, arguments from the derived and from an intermediate constructor, specifier argumentsinheritance_linearization.sol: C3 order differs from a depth-first orderinheritance_super.solandinheritance_diamond.sol:superin functions, modifiers and base constructors,Base.f(), named arguments, a contract that does not overrideinheritance_imported.sol,inheritance_struct_mapping.sol,inheritance_shadowed_state.solCI=true bash test/run_tests.sh: 77 passed, 0 failed, with z3 4.15.4 and with z3 4.8.12 (CI's version until Pin z3 4.15.4 on CI #26). No existing golden changed.lake test,python3 -m pytest Tools/Solidity/test,lake run pbt-determinismand the docs site build pass.return,superin modifiers and base constructors, namedsuperarguments, explicit base calls,superwithout an override, getter overrides, transitive imported bases, and unreachable implementations.Not covered
is Base(7), are unknown values.--via-irinitializes each contract's state variables just before its own constructor.f(uint256)andf(address)) have the same parameter types in the verifier and are rejected, in a single contract too.